import axios from 'axios';
import { ElMessage } from 'element-plus';
import { _msgBox } from '@/utils/msg';

const service = axios.create({
  baseURL: 'http://liujijiself.f3.ttkt.cc',
  // baseURL: 'http://192.168.1.5:8081',
  // baseURL: 'http://192.168.103.214:8081',
  timeout: 10000,
});

service.interceptors.request.use(
  function (config) {
    const token = localStorage.token;
    if (token) {
      config.headers.Authorization = `Bearer ${token}`;
    }
    return config;
  },
  function (error) {
    _msgBox('请求参数错误', 'error');
  },
);

service.interceptors.response.use(
  function (response) {
    return response.data;
  },
  function (error) {
    _msgBox(error.message, 'error');
  },
);

export default service;
